﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.utils;
using l1cs.server.model.Instance;

namespace l1cs.server.serverpackets
{
    class S_HPUpdate : ServerBasePacket
    {
        private readonly IntRange hpRange = new IntRange( 1, 32767 );

        public S_HPUpdate( int currentHp, int maxHp )
        {
            buildPacket( currentHp, maxHp );
        }

        public S_HPUpdate( L1PcInstance pc )
        {
            buildPacket( pc.getCurrentHp(), pc.getMaxHp() );
        }

        public void buildPacket( int currentHp, int maxHp )
        {
            writeC( Opcodes.S_OPCODE_HPUPDATE );
            writeH( hpRange.ensure( currentHp ) );
            writeH( hpRange.ensure( maxHp ) );
            // writeC(0);
            // writeD(GameTimeController.getInstance().getGameTime());
        }

        override
        public byte[] getContent()
        {
            return getBytes();
        }

        override public String getType()
        {
            return "[S] S_HPUpdate";
        }
    }
}
